<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script>
      // 开始计时
      // function startTimer() {
      //   setTimeout(function () {
      //     console.log('============')
      //   }, 3000)
      // }
      function startTimer() {
        //获得系统时间
        var now = new Date() 
        //document.getElementById("timer").innerText = "<h1>"+now+"</h1>"
        document.getElementById("timer").innerHTML = "<h1>"+now+"</h1>"
        t = setTimeout('startTimer()', 1000)
      }

      // 停止计时
      function stopTimer() {
        clearTimeout(t)
      }
    </script>
  </head>
  <body onload="startTimer()">
    <span id="timer"></span>
    <button onclick="startTimer()">开始计时</button>
    <button onclick="stopTimer()">停止计时</button>
  </body>
</html>
